package com.stations.controller;

import com.stations.common.constant.ControllerConstant;
import com.stations.common.web.base.BaseController;
import com.stations.common.web.domain.response.Result;
import com.stations.domain.*;
import com.stations.service.TransmitterSendService;
import com.stations.service.TrasmiterTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Describe: 发射机查询设置管理接口
 * Author: Ljy
 * CreateTime: 2019/10/23
 */
@RestController
@Api(tags = {"发射机查询设置"})
@RequestMapping(ControllerConstant.API_TRANSMITTER_PREFIX + "v1")
public class TransmitterSendController extends BaseController {

    @Resource
    TransmitterSendService transmitterSendService;

    @Resource
    private TrasmiterTaskService sysTrasmiterTaskService;

    /**
     * Describe: 设置发射机通讯参数
     * Param ModelAndView
     * Return 设置发射机通讯参数
     */
    @PostMapping("communication")
    @ApiOperation(value = "设置发射机通讯参数")
    public Result communication(@RequestBody TTransmitter tTransmitter) {
        TTransmitter tnowTTransmitter = transmitterSendService.getTTransmitter(tTransmitter.getStationCode(),tTransmitter.getTransCode());
        tTransmitter.setTransName(tnowTTransmitter.getTransName());
        tTransmitter.setTransIp1(tnowTTransmitter.getTransIp1());
        tTransmitter.setTransHttpPort(tnowTTransmitter.getTransHttpPort());
        return transmitterSendService.communication(tTransmitter);
    }

    /**
     * Describe: 发射任务下发
     * Param ModelAndView
     * Return 发射任务下发
     */
    @PostMapping("playTask")
    @ApiOperation(value = "发射任务下发")
    public Result playTask(@RequestBody TTransmitterTask tTransmitterTask) {
        TTransmitter tnowTTransmitter = transmitterSendService.getTTransmitter(tTransmitterTask.getStationCode(),tTransmitterTask.getTransCode());
        tTransmitterTask.setTransIp(tnowTTransmitter.getTransIp1());
        tTransmitterTask.setTransHttpsPort(tnowTTransmitter.getTransHttpsPort());
        tTransmitterTask.setTransHttpPort(tnowTTransmitter.getTransHttpPort());
        sysTrasmiterTaskService.addTTransmitterTask(tTransmitterTask);
        return transmitterSendService.playTask(tTransmitterTask);
    }

    /**
     * Describe: 运行参数设置
     * Param ModelAndView
     * Return 运行参数设置
     */
    @PostMapping("setStatus")
    @ApiOperation(value = "运行参数设置")
    public Result setStatus(@RequestBody SRunStatus sRunStatus) {
        TTransmitter tnowTTransmitter = transmitterSendService.getTTransmitter(sRunStatus.getStationCode(),sRunStatus.getTransCode());
        return transmitterSendService.setStatus(sRunStatus,tnowTTransmitter);
    }

    /**
     * Describe: 功能参数设置
     * Param ModelAndView
     * Return 功能参数设置
     */
    @PostMapping("setFunction")
    @ApiOperation(value = "功能参数设置")
    public Result setFunction(@RequestBody TTransmitterThreshold tTransmitterThreshold) {
        TTransmitter tnowTTransmitter = transmitterSendService.getTTransmitter(tTransmitterThreshold.getStationCode(),tTransmitterThreshold.getTransCode());
        return transmitterSendService.setFunction(tTransmitterThreshold,tnowTTransmitter);
    }

    /**
     * Describe:发射机时钟校准
     * Param ModelAndView
     * Return 发射机时钟校准
     */
    @PostMapping("clock")
    @ApiOperation(value = "发射机时钟校准")
    public Result clock(@RequestBody TTransmitter tTTransmitter) {
        TTransmitter tnowTTransmitter = transmitterSendService.getTTransmitter(tTTransmitter.getStationCode(),tTTransmitter.getTransCode());
        tnowTTransmitter.setNewTime(tTTransmitter.getNewTime());
        return transmitterSendService.clock(tnowTTransmitter);
    }

    /**
     * Describe:获取发射机时钟
     * Param ModelAndView
     * Return 获取发射机时钟
     */
    @PostMapping("readClock")
    @ApiOperation(value = "获取发射机时钟")
    public Result readClock(@RequestBody TTransmitter tTTransmitter) {
        TTransmitter tnowTTransmitter = transmitterSendService.getTTransmitter(tTTransmitter.getStationCode(),tTTransmitter.getTransCode());
        return transmitterSendService.readClock(tnowTTransmitter);
    }

    /**
     * Describe:运行参数查询
     * Param ModelAndView
     * Return 运行参数查询
     */
    @PostMapping("queryStatus")
    @ApiOperation(value = "运行参数查询")
    public Result queryStatus(@RequestBody SRunStatus sRunStatus) {
        TTransmitter tTTransmitter = transmitterSendService.getTTransmitter(sRunStatus.getStationCode(),sRunStatus.getTransCode());
        return transmitterSendService.queryStatus(tTTransmitter);
    }

    /**
     * Describe:发射机功能参数查询
     * Param ModelAndView
     * Return 发射机功能参数查询
     */
    @PostMapping("queryFunction")
    @ApiOperation(value = "发射机功能参数查询")
    public Result queryFunction(@RequestBody TTransmitterThreshold tTransmitterThreshold) {
        TTransmitter tTTransmitter = transmitterSendService.getTTransmitter(tTransmitterThreshold.getStationCode(),tTransmitterThreshold.getTransCode());
        return transmitterSendService.queryFunction(tTTransmitter);
    }

    /**
     * Describe:发射机功能参数查询
     * Param ModelAndView
     * Return 发射机功能参数查询
     */
    @PostMapping("queryCommunication")
    @ApiOperation(value = "发射机功能参数查询")
    public Result queryCommunication(@RequestBody TTransmitter tTransmitter) {
        TTransmitter tnowTTransmitter = transmitterSendService.getTTransmitter(tTransmitter.getStationCode(),tTransmitter.getTransCode());
        return transmitterSendService.queryCommunication(tnowTTransmitter);
    }

}
